<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="header::head-fragment('用户中心')">
</head>
<body>
<div th:replace="header::header-fragment"></div>

<div class="layui-container fly-marginTop fly-user-main">
  <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="user">
    <li class="layui-nav-item">
      <a th:href="@{${'/userCenter/'+bbsUser.userId}}">
        <i class="layui-icon">&#xe609;</i>
        我的主页
      </a>
    </li>
    <li class="layui-nav-item layui-this">
      <a th:href="@{/myCenter}">
        <i class="layui-icon">&#xe612;</i>
        用户中心
      </a>
    </li>
    <li class="layui-nav-item">
      <a th:href="@{/userSet}">
        <i class="layui-icon">&#xe620;</i>
        基本设置
      </a>
    </li>
  </ul>

  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title" id="LAY_mine">
        <li data-type="mine-jie" lay-id="index" class="layui-this">我发的帖（<span th:text="${myBBSPostCount}">11</span>）</li>
        <li data-type="collection" data-url="/collection/find/" lay-id="collection">我收藏的帖（<span th:text="${myCollectBBSPostCount}">16</span>）</li>
      </ul>
      <div class="layui-tab-content" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">

          <th:block th:if="${#lists.isEmpty(myBBSPostList)}">
            <!-- 无数据时 -->
            <div class="fly-none">没有相关数据</div>
          </th:block>

          <th:block th:unless="${#lists.isEmpty(myBBSPostList)}">
          <ul class="mine-view jie-row">
            <th:block th:each="bbsPost : ${myBBSPostList}">
            <li>
              <a class="jie-title" th:href="@{${'/detail/'+bbsPost.postId}}" target="_blank" th:text="${bbsPost.postTitle}">My-BBS开源啦</a>
              <i th:text="${#dates.format(bbsPost.createTime, 'yyyy/MM/dd HH:mm:ss')}">2021/08/01</i>
              <a class="mine-edit" th:href="@{${'/editPostPage/'+bbsPost.postId}}">编辑</a>
              <a class="mine-del" href="##" th:onclick="'delPost('+${bbsPost.postId}+')'">删除</a>
              <em><th:block th:text="${bbsPost.postViews}"></th:block>阅/<th:block th:text="${bbsPost.postComments}"></th:block>答</em>
            </li>
            </th:block>
          </ul>
          </th:block>
          <div id="LAY_page"></div>
        </div>
        <div class="layui-tab-item">

          <th:block th:if="${#lists.isEmpty(collectRecords)}">
            <!-- 无数据时 -->
            <div class="fly-none">没有相关数据</div>
          </th:block>

          <th:block th:unless="${#lists.isEmpty(collectRecords)}">
            <ul class="mine-view jie-row">
              <th:block th:each="bbsPost : ${collectRecords}">
                <li>
                  <a class="jie-title" th:href="@{${'/detail/'+bbsPost.postId}}" target="_blank" th:text="${bbsPost.postTitle}">My-BBS开源啦</a>
                  <em><th:block th:text="${bbsPost.postCollects}"></th:block>收藏</em>
                </li>
              </th:block>
            </ul>
          </th:block>
          <div id="LAY_page1"></div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="fly-footer">
  <p>My-BBS社区 2021 &copy; <a href="https://github.com/ZHENFENG13/My-BBS" target="_blank">十三</a></p>
</div>

<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript">
    layui.use(['layer', 'element', 'jquery'], function () {
        var layer = layui.layer, $ = layui.$, element = layui.element;
        var device = layui.device();
        //阻止IE7以下访问
        if (device.ie && device.ie < 8) {
            layer.alert('如果您非得使用 IE 浏览器访问社区，那么请使用 IE8+');
        }
        //搜索
        $('.fly-search').on('click', function () {
            layer.open({
                type: 1
                , title: false
                , closeBtn: false
                //,shade: [0.1, '#fff']
                , shadeClose: true
                , maxWidth: 10000
                , skin: 'fly-layer-search'
                , content: ['<form action="/index">'
                    , '<input autocomplete="off" placeholder="搜索内容，回车跳转" type="text" name="keyword">'
                    , '</form>'].join('')
                , success: function (layero) {
                    var input = layero.find('input');
                    input.focus();
                    layero.find('form').submit(function () {
                        var val = input.val();
                        if (val.replace(/\s/g, '') === '') {
                            return false;
                        }
                        input.val(input.val());
                    });
                }
            })
        });

        window.delPost = function (postId) {
            var $ = layui.$;
            $.ajax({
                type: 'POST',//方法类型
                url: '/delPost/'+postId,
                success: function (result) {
                    if (result.resultCode == 200) {
                        layer.confirm('删除成功!将刷新本页面...', {icon: 3, skin: 'layui-layer-molv',title:'提示'}, function(index){
                            layer.close(index);
                            window.location.reload();
                        });
                    } else {
                        layer.msg(result.message);
                    }
                    ;
                },
                error: function () {
                    layer.alert('操作失败!', {title: '提醒', skin: 'layui-layer-molv', icon: 2});
                }
            });
        }
    });
</script>
</body>
</html>